/**
 * 
 */
package co.gov.medellin.sdep.sisdep.regulacion.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.regulacion.exception.EventoVistoBuenoException;
import co.gov.medellin.sdep.sisdep.regulacion.exception.EventoVistoBuenoRuntimeException;
import co.gov.medellin.sdep.sisdep.regulacion.exception.descriptor.EventoVistoBuenoMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.EventoVistoBueno;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IEventoVistoBuenoDAOT;

/**
 * @author Usuario
 *
 */
public class EventoVistoBuenoServiceImpl extends BaseService implements IEventoVistoBuenoService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private IEventoVistoBuenoDAOT eventoVistoBuenoDAO;

	/**
	 * 
	 */
	public EventoVistoBuenoServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(EventoVistoBueno eventoVistoBueno) throws EventoVistoBuenoException {
		try{
			eventoVistoBueno.setUsuarioCrea(getPrincipalUser());					
			getEventoVistoBuenoDAO().insert(eventoVistoBueno);
		}catch (Exception e) {
			Object [] infoError = {
				eventoVistoBueno.getCodigo()
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new EventoVistoBuenoException(new EventoVistoBuenoMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new EventoVistoBuenoException(new EventoVistoBuenoMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(EventoVistoBueno eventoVistoBueno) throws EventoVistoBuenoException {
		try{
			eventoVistoBueno.setUsuarioModifica(getPrincipalUser());
			getEventoVistoBuenoDAO().update(eventoVistoBueno);
		}catch (Exception e) {
			Object [] infoError = {
				eventoVistoBueno.getCodigo()
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new EventoVistoBuenoRuntimeException(new EventoVistoBuenoMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new EventoVistoBuenoRuntimeException(new EventoVistoBuenoMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(EventoVistoBueno eventoVistoBueno) throws EventoVistoBuenoException {
		try {
			eventoVistoBueno.setUsuarioModifica(getPrincipalUser());
			eventoVistoBueno.setFechaModifica(new Date());
			getEventoVistoBuenoDAO().delete(eventoVistoBueno);
		}catch (Exception e) {
			Object [] infoError = {
				eventoVistoBueno.getCodigo()
			};
			throw new EventoVistoBuenoRuntimeException(new EventoVistoBuenoMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, EventoVistoBueno eventoVistoBueno) throws EventoVistoBuenoException {
		try{
			//return getEventoVistoBuenoDAO().getAllEventoVistoBuenoPaginated(start, max, criteria);
			return getEventoVistoBuenoDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new EventoVistoBuenoRuntimeException(new EventoVistoBuenoMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	public final List loadByIdEvento(int start,int max, EventoVistoBueno eventoVistoBueno) throws EventoVistoBuenoException {
		try{
			//return getEventoVistoBuenoDAO().getAllEventoVistoBuenoPaginated(start, max, criteria);
			return getEventoVistoBuenoDAO().loadByIdEvento(eventoVistoBueno);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new EventoVistoBuenoRuntimeException(new EventoVistoBuenoMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	
	/**
	 * 
	 */
	public final EventoVistoBueno get(long id) throws EventoVistoBuenoException {
		try{
			return getEventoVistoBuenoDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new EventoVistoBuenoRuntimeException(new EventoVistoBuenoMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public IEventoVistoBuenoDAOT getEventoVistoBuenoDAO() {
		return eventoVistoBuenoDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setEventoVistoBuenoDAO(IEventoVistoBuenoDAOT eventoVistoBuenoDAO) {
		this.eventoVistoBuenoDAO = eventoVistoBuenoDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
